package com.baiye.www.controller;



import com.baiye.www.annotation.Controller;
import com.baiye.www.annotation.RequestMapping;
import com.baiye.www.context.WebContext;
import com.baiye.www.view.Data;
import com.baiye.www.view.View;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: baiye
 * @Date: 2021/07/18/16:20
 * @Description:
 */
@Controller
public class LoginController {


    //使用RequestMapping注解指明forward1方法的访问路径
    @RequestMapping("/login2")
    public View forward1() {


        System.out.println("login2...");

        HttpServletRequest request = WebContext.requestHolders.get();

        String username = request.getParameter("username");
        String password = request.getParameter("password");


        //执行完forward1方法之后返回的视图
        return new View("Login2.jsp");
    }

    /**
     * 处理登录请求,接受参数
     * @return
     */
    @RequestMapping("/login")
    public View login(){

        System.out.println("login...");

        //首先获取当前线程的request对象
        HttpServletRequest request = WebContext.requestHolders.get();

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        //将数据存储到ViewData中
        Data viewData = new Data();
        viewData.put("msg","欢迎你"+username);
        // 相当于
        // request.setAttribute("msg","欢迎你"+username);


        return new View("index.jsp");
    }






}
